package com.ms.service.module.fish;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import com.ms.service.module.fish.utils.FishGameUtils;

/**
 * 异步延时执行
 * 需要调用延迟执行的时候可使用，避免在代码里面直接调用Thread.sleep()方法
 * 
 * @author andylo25 wrote on 2018/6/11.
 */
public class TimerManager {

	private volatile static ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);
	
	public static ScheduledFuture<?> schedule(Runnable action, long delay){
		return executorService.schedule(action, delay, TimeUnit.MILLISECONDS);
	}
	
	public static ScheduledFuture<?> scheduleAtFixedRate(Runnable action,long initialDelay, long period ){
		return executorService.scheduleAtFixedRate(action, initialDelay,period, TimeUnit.MILLISECONDS);
	}
	
	public static ScheduledFuture<?> scheduleWithFixedDelay(Runnable action,long initialDelay, long period ){
		return executorService.scheduleWithFixedDelay(action, initialDelay,period, TimeUnit.MILLISECONDS);
	}
	
	
}
